<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>{{detailOption.name}}-记录核销</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="editForm" label-width="100px" ref="editForm">
          <el-row>
            <el-col :span="18">
              <el-form-item label="教具名称:">
                {{detailOption?detailOption.name:'--'}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <el-form-item label="教具位置:">
                <el-select v-model="editForm.postion_id" placeholder="教具位置" style="width: 100%;">
                  <el-option :value="item.class_id" v-for="(item, index) in goodsList" :key="index" :label="item.name"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <el-form-item label="核销数量:">
                <el-input v-model="editForm.number" auto-complete="off" placeholder="核销数量"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <el-form-item label="核销去向:">
                <el-input v-model="editForm.title" auto-complete="off" placeholder="核销去向"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <el-form-item label="核销描述:">
                <el-input v-model="editForm.desct" auto-complete="off" placeholder="核销描述" type="textarea"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small" >返回</el-button>
        <el-button size="small" type="primary" @click.native="editSubmit">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props: ['visible','detailOption'], // commoent 学生点评 collection 学生采集
  components: {
  },
  data() {
    return {
      dialogVisible: false,
      editForm: {
        postion_id: '',
        number: '',
        title: '',
        desct: ''
      }, // 编辑界面数据
      goodsList: [], // 教具位置
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if(this.visible){
        this.teachingArea()
      }else{
        this.goodsList = []
        for(let i in this.editForm){
          this.editForm[i] = '';
        }
      }
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option){
      return JSON.parse(JSON.stringify(option))
    },
    // 提交数据
    async editSubmit () {
      // 验证信息
      let dataOption = this.getJson(this.editForm)
      if(!dataOption.postion_id){
        this.$message.error('选择教具位置')
        return
      }
      if(!dataOption.number){
        this.$message.error('核销数量')
        return
      }
      if(!dataOption.title){
        this.$message.error('核销去向')
        return
      }
      if(!dataOption.title){
        this.$message.error('核销描述')
        return
      }
      let data = await this.$post(this.api.tools_scrap_add, dataOption);
      if (!data.code) {
        this.$message.success('核销成功！')
        this.$emit('InitFn')
        this.closePOpup()
      } else {
        this.$message.error(data.msg)
      }
    },
    // 教具位置
    async teachingArea () {
      let data = await this.$fetch(this.api.tools_postion, {tools_id: this.detailOption.id});
      if (!data.code) {
        let list = []
        for (let i in data.list.data) {
          let array_ = {}
          if (data.list.data[i].class_id === 0) {
            array_.name = '总仓'
          } else {
            array_.name = data.list.data[i].classes.class_name
          }
          array_.class_id = data.list.data[i].id
          list.push(array_)
        }
        this.goodsList = list

      } else {
        this.$message.error(data.msg)
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}
.hearder-search{
  display: flex;
  align-items: center;
}
</style>


